//package com.xiaocikuai.smallchunks.controller.Recode;
//
//import com.xiaocikuai.smallchunks.entity.Recode.Recode;
//import com.xiaocikuai.smallchunks.service.Recode.RecodeService;
//import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
//import jakarta.annotation.Resource;
//import org.springframework.web.bind.annotation.*;
//
////学习记录
//@RestController
//@RequestMapping("/api/recode")
//@CrossOrigin
//public class RecodeController {
//    @Resource
//    private RecodeService recodeService;
//
//    //学习记录添加
//    @PostMapping("/add")
//    public Resultd recodeAdd(@RequestBody Recode recode, @RequestHeader("Authorization") String token){
//            return Resultd.ok().data("info",recodeService.learnRecode(recode,token));
//    }
//
//
//}
package com.xiaocikuai.smallchunks.controller.Recode;

import com.xiaocikuai.smallchunks.entity.Card.CardChunks;
import com.xiaocikuai.smallchunks.entity.Recode.Recode;
import com.xiaocikuai.smallchunks.service.Recode.RecodeService;
import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 学习记录
@Api(tags = "学习记录控制器")
@RestController
@RequestMapping("/api/recode")
@CrossOrigin
public class RecodeController {

    @Resource
    private RecodeService recodeService;

    @ApiOperation(value = "添加学习记录")
    @PostMapping("/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recode", value = "学习记录信息", required = true, dataType = "Recode", paramType = "body"),
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    })
    public Resultd recodeAdd(@RequestBody Recode recode, @RequestHeader("Authorization") String token){
        return Resultd.ok().data("info",recodeService.learnRecode(recode,token));
    }



    @ApiOperation(value = "获取每日需复习的单词")
    @PostMapping("/reviewById")
    @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    public Resultd review(@RequestHeader("Authorization") String token, @RequestBody Recode recode) {
        List<CardChunks>  plansList = recodeService.getReview(recode.getPid(), token);
        if (plansList!= null) {
            return Resultd.ok().data("info", plansList);
        } else {
            return Resultd.ok().data("info","今日没有需要复习的单词");
        }
    }


    @ApiOperation(value = "获取每日需复习的单词")
    @PostMapping("/review")
    @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    public Resultd review(@RequestHeader("Authorization") String token) {
        List<CardChunks> plansList = recodeService.getReviewWords(token);
        if (plansList!= null) {
            return Resultd.ok().data("info", plansList);
        } else {
            return Resultd.ok().data("info","今日没有需要复习的单词");
        }
    }

    @ApiOperation(value = "随便刷刷")
    @PostMapping("/getRandomList")
    @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    public Resultd getRandomList(@RequestHeader("Authorization") String token, @RequestBody Recode recode) {
        List<CardChunks> list = recodeService.getRandomList(token, recode.getPid(), recode.getLevel());
        if (list!= null) {
            return Resultd.ok().data("info", list);
        } else {
            return Resultd.error().data("info","失败");
        }
    }





}